package com.sf.fy.uav.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sf.fy.uav.common.enums.ScenicSpotStatusEnum;
import com.sf.fy.uav.common.request.operate.BusinessReq;
import com.sf.fy.uav.common.request.operate.MerchantReq;
import com.sf.fy.uav.common.response.operational.BusinessRes;
import com.sf.fy.uav.common.response.operational.MerchantRes;
import com.sf.fy.uav.common.utils.RespJsonPageData;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.entity.Business;
import com.sf.fy.uav.service.IBusinessService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LTQ
 * @since 2023-12-07
 */
@RestController
@RequestMapping("/sys/business")
public class BusinessRest {


    @Autowired
    private IBusinessService iBusinessService;

    public List<Business> getBusinesses() {
        return iBusinessService.getBusinesses();
    }

    public List<Business> getBusinessesByScenicSpotId(String scenicSpotId) {
        return iBusinessService.getBusinessesByScenicSpotId(scenicSpotId);
    }
    public RespJsonPageData<BusinessRes> getBusiness(BusinessReq businessReq) {
        return iBusinessService.getPageBusiness(businessReq);
    }

    public Rs<Integer> delBusiness(MerchantReq merchantReq) {
        return iBusinessService.deletedBusiness(merchantReq);
    }
    public RespJsonPageData<MerchantRes> getMerchant(MerchantReq merchantReq) {
        return iBusinessService.getPageMerchant(merchantReq);
    }

    public Rs<Integer> addMerchant(MerchantReq merchantReq) {
        return iBusinessService.save(merchantReq);
    }

    public Rs<Integer> editMerchant(MerchantReq merchantReq) {
        return iBusinessService.updateById(merchantReq);
    }
    public Rs<List<Business>> queryBusinessName(String id, String name){
        LambdaQueryWrapper<Business> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(StringUtils.isNotBlank(name) ,Business::getName,name)
                .eq(StringUtils.isNotBlank(id),Business::getId,id)
                .eq(Business::getStatus, ScenicSpotStatusEnum.NORMAL.getValue());
        return Rs.success(iBusinessService.list(wrapper));
    }

    public List<Business> getBusinessesByBusinessIds(Set<String> businessIds) {
        return iBusinessService.getBusinessesByBusinessIds(businessIds);
    }
    public List<Business> getBusinessesByBusinessId(String businessId) {
        return iBusinessService.list(new QueryWrapper<Business>().eq("id",businessId));
    }

    public List<Business> getBusinessesByScenicSpotIdSet(Set<String> spotIdSet) {
        return iBusinessService.list(new QueryWrapper<Business>().in("scenic_spot_id",spotIdSet));
    }
    public Business getBusinessesByIdAndNoByStatus(String id) {
        return iBusinessService.getById(id);
    }
    public Page<Business> getBusinessesPage(Integer page, Integer size, LambdaQueryWrapper<Business> wrapper) {
        return iBusinessService.page(new Page<>(page,size),wrapper);
    }
}
